{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    {include file='public:left-menu'/}
    <!--End 左侧导航-->
    <!--头部信息-->
    {include file='public:nav-header' title="内容管理" subTitle="添加编辑文章"/}
    <!--End 头部信息-->
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-body">
                <form method="post" id="submit-form" class="row">
                  <div class="form-group col-md-12">
                    <label class="form-title"><em class="require">*</em>文章标题</label>
                    <input type="text" class="form-control" name="title" value="{$info.title}" placeholder="请输入文章标题"/>
                    <span class="error" id="err_title"></span>
                  </div>
                  <div class="form-group col-md-12">
                    <label class="form-title">文章描述</label>
                    <textarea class="form-control" name="description" rows="3" placeholder="请输入文章描述">{$info.description}</textarea>
                  </div>
                  <div class="form-group col-md-12">
                    <label class="form-title"><em class="require">*</em>文章内容</label>
                    <textarea class="ueditor" id="content" name="content" placeholder="请输入文章内容">{$info.content}</textarea>
                    <span class="error" id="err_content"></span>
                  </div>
                  <div class="form-group col-md-12">
                    <input type="hidden" name="{$info.pk}" value="{$info[$info.pk]}">
                    <button type="button" class="btn-theme submit-btn">确定</button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    <!--End 页面主要内容-->
  </div>
</div>
{load href="__ADMIN__/plugin/Ueditor/ueditor.config.js"/}
{load href="__ADMIN__/plugin/Ueditor/ueditor.all.min.js"/}
{load href="__ADMIN__/plugin/Ueditor/lang/zh-cn/zh-cn.js"/}
<script type="text/javascript">
  var url="{:url('Ueditor/index',['savePath'=>'article'])}";
  var ue = UE.getEditor('content',{
    serverUrl :url,
    zIndex: 999,
    initialFrameWidth: "100%", //初化宽度
    initialFrameHeight: 300, //初化高度
    focus: false, //初始化时，是否让编辑器获得焦点true或false
    maximumWords: 99999, //允许的最大字符数 'fullscreen',
    removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',
    pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
    autoHeightEnabled: true
  });
  $(function(){
    $('.submit-btn').click(function () {
      $('span.error').hide();
      $('.form-group').removeClass('has-error');
      var url = "{:url('Content/add_edit_article',[$info.pk=>$info[$info.pk]])}";
      var data = $('#submit-form').serialize();
      $.ajax({
        type: "POST",
        url: url,
        data: data,
        dataType: 'json',
        success: function (data) {
          if (data.code == 1) {
            showSuccessMsg(data.msg, function () {
              if (data.data.url) {
                location.href = data.data.url;
              }
            });
          } else if (data.code == 10) {
            showErrorMsg(data.msg);
            $.each(data.data.result, function(index, item) {
              $('#err_' + index).text(item).show();
              $('#err_' + index).parent().addClass('has-error');
            });
          } else {
            showErrorMsg(data.msg);
          }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          showErrorMsg("网络失败，请刷新后重试!");
        }
      });
    });
  });
  function call_back(fileurl_tmp,fileurl_id)
  {
    $("[name="+fileurl_id+"]").val(fileurl_tmp);
    $("#"+fileurl_id).attr('src', fileurl_tmp);
  }
</script>
</body>
</html>
